<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use App\User;
use App\Models\Cart;
use App\Models\Article;

class Buy extends Model
{
    use SoftDeletes;
    
    public function info()
    {
        if($this->item_type == 'cart')
            return $this->hasOne(Cart::class, 'id', 'item_id');
        else 
            return $this->hasOne(Article::class, 'id', 'item_id');
    }
    
    public function user()
    {
        return $this->hasOne(User::class, 'id', 'user_id');
    }
    
    
    
}
